package com.feng.handler;

import com.feng.domain.ResponseResult;
import com.feng.enums.AppHttpCodeEnum;
import com.feng.exception.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(SystemException.class)
    public ResponseResult systemException(SystemException e){
        //打印错误信息
        log.error("出现了异常!  {}",e);

        //返回
        return ResponseResult.errorResult(e.getCode(), e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception e){
        //打印错误信息
        log.error("出现了异常!  {}",e);

        //返回
        return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, e.getMessage());
    }
}
